package pure.ui 
{
	import pure.ui.core.Component;
	import pure.ui.core.IPopUp;
	import pure.ui.skins.IBackgroundSkin;
	import pure.ui.skins.ISkin;
	import pure.ui.skins.SkinColor;
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Point;
	
	/**
	 * 面板
	 * @author Des
	 * <皮肤种类> ---- IBackgroundSkin
	 * 
	 */
	
public class Panel extends Image implements IPopUp
{
	public function Panel(x:Number, y:Number, size:Point , skin:ISkin = null, mouseEnabled:Boolean = false, mouseChildren:Boolean = true) 
	{
		super(x, y, size,skin,mouseEnabled,mouseChildren);
		this.mouseEnabled = mouseEnabled;
		this.mouseChildren = this._container.mouseChildren = mouseChildren;
		
	}
	

	
	/*cache*/
	
	protected var _container:Sprite;
	
	protected var _mask:Shape;


	/**
	 * 大小
	 * @param w			组件宽度
	 * @param h			组件高度
	 **/
	override public function setSize(w:Number,h:Number):void
	{
		super.setSize(w, h);
		_mask.graphics.clear();
		_mask.graphics.beginFill(0, 1);
		_mask.graphics.drawRect(0,0,this._width, this._height);
	}
	
	/**
	 * 毁灭
	 */
	override public function destroy():void
	{
		removeChild(_container);
		_container = null;
		removeChild(_mask);
		_mask = null;
		super.destroy();
	}
	
	/**
	 * 关闭/隐藏窗口
	 * @param gc		是否回收
	 **/
	public function hide(gc:Boolean):void
	{
		// 回收
		if (gc)
		{
			this.destroy();
		}
		// 隐藏
		else
		{
			this.parent.removeChild(this);
		}
	}
	
	/**
	 * 添加元素
	 * @param element		子元素
	 **/
	public function addElement(element:DisplayObject):void 
	{
		_container.addChild(element) 
	}

	/**
	 * 添加元素于指定层
	 * @param element		子元素
	 * @param index			索引
	 **/
	public function addElementAt(element:DisplayObject, index:int):void
	{ 
		_container.addChildAt(element, index)
	}

	/**
	 * 删除元素
	 * @param element		子元素
	 **/
	public function removeElement(element:DisplayObject):void
	{
		_container.removeChild(element)
	}

	/**
	 * 添加指定层元素
	 * @param index			索引
	 **/
	public function removeElementAt(index:int):void 
	{
		_container.removeChildAt(index);
	}
	
	
	
	
	
	/* ----------------------------------------------------    private    ----------------------------------------------------*/
	

	
	
	
	/**
	 * 子元素
	 */
	override protected function _addChildren():void
	{
		super._addChildren();
		
		// 容器
		this._container = new Sprite();
		this._container.mouseEnabled = false;
		addChild(this._container);
		
		// 遮罩
		_mask = new Shape();
		addChild(_mask);
		this._container.mask = _mask;
	}
}

}